from langchain_openai import ChatOpenAI
import os

base_url = os.environ.get("BAOCLOUD_DS_BASE_URL")
model_name = os.environ.get("BAOCLOUD_DS_MODEL_NAME")
os.environ["OPENAI_API_KEY"] = os.getenv("BAOCLOUD_DS_API_KEY")

model = ChatOpenAI(base_url=base_url, model_name=model_name)
result = model.invoke("你是谁？")
print(result.content)

chunk = model.stream("请介绍一下汉武帝，字数控制在100字以内。")
for chunk in chunk:
    print(chunk.content, end="", flush=True)

